// the second test case of 1.in raises a tricky problem. prev[H][I] = prev[I][H] should be true. However, we cancel the loop by making both of them false
#include <iostream>
#include <string.h>
#include <string>
#include <algorithm>
#include <deque> 

using namespace std;

#define oo 1000000000

int h, w, m;
string s[30];
bool prev[26][26];
bool present[26];
int rank[26];
int mini[26], minj[26], maxi[26], maxj[26];

void attempt(int u, string res)
{
	res = res + (char) (u + 'A');

	if ((int) res.size() == m)
	{
		cout << res << endl;
		return;
	}

	for (int v = 0; v < 26; v++)
		if (prev[u][v])	rank[v]--;

	present[u] = false;
	for (int v = 0; v < 26; v++)
		if (present[v] && rank[v] == 0) attempt(v, res);
	present[u] = true;

	for (int v = 0; v < 26; v++) 
		if (prev[u][v]) rank[v]++;
}

int main()
{
	while (cin >> h >> w)
	{
		memset(prev, false, sizeof(prev));
		memset(present, false, sizeof(present));
		memset(rank, 0, sizeof(rank));
		for (int i = 0; i<  26; i++)
		{
			mini[i] = oo;
			minj[i] = oo;
			maxi[i] = -oo;
			maxj[i] = -oo;
		}

		for (int i = 0; i < h; i ++) 
		{
			cin >> s[i];
			for (int j = 0; j < w; j++)
			{
				if ('A' <= s[i][j] && s[i][j] <= 'Z')
				{
					int ind = s[i][j] - 'A';
					mini[ind] = min(mini[ind], i);
					minj[ind] = min(minj[ind], j);
					maxi[ind] = max(maxi[ind], i);
					maxj[ind] = max(maxj[ind], j);
					present[ind] = true;
				}
			}
		}

		for (int c = 0; c < 26; c++)
			if (present[c])
			{
				for (int i = mini[c]; i <= maxi[c]; i++)
				{
					int j = minj[c];
					if (s[i][j] -'A' != c) prev[c][s[i][j] - 'A'] = true;
					j = maxj[c];
					if (s[i][j] -'A' != c) prev[c][s[i][j] - 'A'] = true;
				}

				for (int j = minj[c]; j <= maxj[c]; j++)
				{
					int i = mini[c];
					if (s[i][j] -'A' != c) prev[c][s[i][j] - 'A'] = true;
					i = maxi[c];
					if (s[i][j] -'A' != c) prev[c][s[i][j] - 'A'] = true;
				}
			}
	
		m = 0;
		for (int c = 0; c < 26; c++)
			if (present[c]) m++;

		for (int c = 0; c < 26; c++)
			if (present[c])
			{
				for (int i = 0; i < 26; i++)
					if (prev[c][i]) rank[i]++;
			}

		for (int c = 0; c < 26; c++)
			if (present[c] && rank[c] == 0)	 attempt(c, "");
	}

	

	return 0;
}
